home *** CD-ROM | disk | FTP | other *** search
/ New Star Software Collection / NSS_Collection.iso / 3-170 dbase 10 for windows / 1.ima / SAMPLES.PAK / BINTREE.PRG < prev    next >
Text File  |  1993-07-26  |  1KB  |  77 lines

  1. set talk off
  2. use clients
  3.  
  4. x = new tree(contact,client_Id)
  5. ? "Scanning database and building binary tree.."
  6. ?
  7.  
  8. scan
  9.   ?? '.'
  10.   d=x.addtree(contact,client_Id)
  11. endscan
  12.  
  13.  
  14.  
  15.  
  16. wait "Press any key to begin in-order traversal of binary tree..."
  17.  
  18. d=x.inOrder()
  19.  
  20.  
  21. class tree
  22.    parameter newKey, newValue
  23.    member key, val, left, right, insert
  24.  
  25.    * Constructor
  26.  
  27.    key = newKey
  28.    val = newValue
  29.    left = .f.
  30.    right = .f.
  31.  
  32.    function inOrder
  33.  
  34.       * left
  35.       if .not. empty(left)
  36.          d=left.inOrder()
  37.       endif
  38.  
  39.       * itself
  40.       ?  key, val
  41.  
  42.       * right
  43.       if .not. empty(right)
  44.          d=right.inOrder()
  45.       endif
  46.       return (0)
  47.  
  48.    function addtree
  49.    parameter newKey, newValue
  50.  
  51.       d=insert(new tree(newKey, newValue))
  52.       return (0)
  53.  
  54.    function insert
  55.    parameter o
  56.  
  57.       if o.key < key
  58.  
  59.          if (empty(left))
  60.             left = o
  61.             return(o)
  62.          else
  63.             return(left.insert(o))
  64.          endif
  65.       else
  66.          if (empty(right))
  67.             right = o
  68.             return(o)
  69.          else
  70.             return(right.insert(o))
  71.          endif
  72.       endif
  73.  
  74. endclass
  75.  
  76.  
  77.